<form id="articleForm" autocomplete="off">
	<input type="hidden" name="article.id" value="0"/>
	<ul class="form">
		<li>
			<label class="label">标题：</label><input type="text" name="article.title" class="input border-radius_4px"/>
		</li>
		<li>
			<label class="label">分类：</label>
			<select name="article.category" class="border-radius_4px"></select>
			<select name="article.artType" class="border-radius_4px"></select>								
		</li>
		<li>
			<label class="label">源地址：</label><input type="text" name="article.sourceUrl" class="input border-radius_4px"/>
		</li>
		<li>
			<label class="label">简介：</label><textarea name="article.memo" class="border-radius_4px"></textarea>
		</li>
		<li>
			<label class="label">标题图片：</label><input type="text" name="article.titlePic" class="input border-radius_4px"/><span id="selectImg" class="icon icon-edit"></span>
		</li>
		<li>
			<label class="label">状态：</label>
			<select name="article.status" class="border-radius_4px"></select>							
		</li>						
	</ul>
</form>
<script type="text/javascript">
COMM.ns("Article");
$(document).ready(function(){
	var articleId = $("#articleForm input[name='article.id']");
	var category = $("#articleForm select[name='article.category']");
	var artType = $("#articleForm select[name='article.artType']");
	var articleState = $("#articleForm select[name='article.status']");
	var artTitle = $("#articleForm input[name='article.title']");
	var artSourceUtl = $("#articleForm input[name='article.sourceUrl']");
	var artMemo = $("#articleForm textarea[name='article.memo']");
	var artTitlePic = $("#articleForm input[name='article.titlePic']");
	
	//var optionsIsLoad = 0;
	$.getJSON("/admin/config/cg_listCategory.do", function(data){
		renderCategorySelect(data);
		//optionsIsLoad ++;
	});
	
	$.getJSON("/comm/getArticleState.do", function(data){
		var state = data.articleState;
		for(var id in state){
			articleState.append("<option value='"+id+"'>"+state[id]+"</option>");
		}
		//optionsIsLoad ++;
	});
	
	var renderCategorySelect = function(data){
		dataMap = {};
		categorysData = data.categorys;
		catTemp = $("<select></select>");
		for(var i=0;i<categorysData.length;i++){
			catTemp.append("<option value='"+categorysData[i].id+"'>"+categorysData[i].name+"</option>");
			dataMap[categorysData[i].id] = categorysData[i].subCategory;
		}
		renderSubSelect(categorysData[0].id);
		category.append(catTemp.children()).change(function(){
			renderSubSelect($(this).val());
		});
		category.val(categorysData[0].id);
		catTemp = null;
	};
	
	var renderSubSelect = function(categoryId){
		subData = dataMap[categoryId];
		artType.empty();
		if(subData.length == 0){
			artType.append("<option value='-1000'>--没有子项--</option>");
		} else {
			for(var i=0;i<subData.length;i++){
				artType.append("<option value='"+subData[i].id+"'>"+subData[i].name+"</option>");
			}					
		}	
	};
	Article.setValue = function(article){
		//var interval = setInterval(function(){
		//	if(optionsIsLoad == 2){
				articleId.val(article.id)
				category.select(article.category);
				renderSubSelect(article.category);
				artType.select(article.artType);
				articleState.select(article.status);
				artTitle.val(article.title);
				artSourceUtl.val(article.sourceUrl);
				artMemo.val(article.memo);
				artTitlePic.val(article.titlePic);
			//	clearInterval(interval);
	//		}
		//}, 20);
	};
	//打开图片选择组件
	$("#selectImg").click(function(){
		$.dialog({
			id:'selectDG',
			title:'文章修改',
		    content: "<div id='imgSelectDialog' style='width:500px;height:300px;overflow:auto;'></div>",
			initFn : function(){
				ImgList.Object.init("#imgSelectDialog");
			}
		});
	});
	ImgList.Object.onclick = function(imgPath){
		artTitlePic.val(imgPath);
		$.dialog({id:'selectDG'}).close();
	};
});
</script>